package nz.ac.massey.spidernetpn.database.tests;


import static org.junit.Assert.*;

import java.io.IOException;
import java.net.URL;
import java.util.List;

import nz.ac.massey.spidernetpn.database.GraphDatabase;
import nz.ac.massey.spidernetpn.graph.SPNGraph;

import org.junit.*;

import edu.uci.ics.jung.graph.DirectedGraph;
import edu.uci.ics.jung.graph.DirectedSparseMultigraph;


public class DatabaseTestCases {

	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
	}

	@AfterClass
	public static void tearDownAfterClass() throws Exception {
	}

	@Before
	public void setUp() throws Exception {
		testGraph = null;
		//System.out.println("In setup");
		URL rootNode = new URL("http://www.massey.ac.nz");
		URL node1 = new URL("http://www.massey.ac.nz");
		URL node2 = new URL("https://alumnionline.massey.ac.nz/");
		URL node3 = new URL("https://secure.mymassey.com/");
		
		URL node4 = new URL("http://alumnionline.massey.ac.nz/NetCommunity/Page.aspx?pid=334");
		URL node5 = new URL("http://masseynews/massey/about-us/news/print-publications/definingnz.cfm");
		
		testGraph = new DirectedSparseMultigraph<URL, Integer>();
		
		//loadedGraph.addVertex(rootNode);
		testGraph.addEdge(1, rootNode, node1);

		testGraph.addEdge(2, rootNode, node2);
		testGraph.addEdge(3, rootNode, node3);
		testGraph.addEdge(4, node2, node4);
		testGraph.addEdge(5, node2, node5);
	
	}
	
	private DirectedGraph<URL, Integer> testGraph;
	
	
	//New Save graph
	@Test
	public void test4(){
		GraphDatabase testDB = new GraphDatabase();

		try {
			assertTrue(testDB.saveGraph("Test Graph2", testGraph));
		} catch (Exception e) {
			assertTrue(false);
		}
		
		
	}
	
	//Load Graph
	@Test
	public void test2(){
		GraphDatabase testDB = new GraphDatabase();
		DirectedGraph<URL, Integer> testGraph2 = null;
		try {
			testGraph2 = testDB.loadCustomGraph("Test Graph");
		} catch (IOException e) {
			e.printStackTrace();
		}	
		assertTrue(testGraph2.equals(testGraph));
	}
	
	
	
	@Test
	public void test3(){	
		GraphDatabase testDB = new GraphDatabase();	
		List testList = testDB.getListOfStoredGraphs();	
		assertTrue(testList.size()>0);
	}
	

	@After
	public void tearDown() throws Exception {
	}

}
